package com.bz.xtcx.manager.config;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;
import org.springframework.jms.support.converter.MappingJackson2MessageConverter;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.jms.support.converter.MessageType;

import javax.jms.ConnectionFactory;
import javax.jms.Destination;

@Configuration
public class ActiveMQConfig {
//    @Bean
//    public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ConnectionFactory connectionFactory,
//                                                                    DefaultJmsListenerContainerFactoryConfigurer configurer) {
//        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
//        // This provides all boot's default to this factory, including the message converter
//        configurer.configure(factory, connectionFactory);
//        // You could still override some of Boot's default if necessary.
//        return factory;
//    }

    @Bean // Serialize message content to json using TextMessage
    public MessageConverter jacksonJmsMessageConverter() {
        MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
        converter.setTargetType(MessageType.TEXT);
        converter.setTypeIdPropertyName("_type");
        return converter;
    }

    @Bean
    public Destination respMeetingMobileQueue(){
        return new ActiveMQQueue("jmrh_resp_meeting_mobile_queue");
    }

    @Bean
    public Destination respMeetingEmailQueue(){
        return new ActiveMQQueue("jmrh_resp_meeting_email_queue");
    }

    @Bean
    public Destination reqMeetingMobileQueue(){
        return new ActiveMQQueue("jmrh_req_meeting_mobile_queue");
    }

    @Bean
    public Destination reqMeetingEmailQueue(){
        return new ActiveMQQueue("jmrh_req_meeting_email_queue");
    }

    @Bean
    public Destination refUserMeetingQueue(){
        return new ActiveMQQueue("jmrh_ref_user_meeting_queue");
    }
}
